%zhp 6/15修改
%by ylx clq
addpath functions;
% Global Variables are avaliable for ALL FUNCTIONS
% >>> global variables settings
global P J I ci cI r LAMBDA CURRENT PIEs EYin ProfitPart EYI S
% P = [.1, .5, .9]; % for test only
LAMBDA = 3; % lambda * dt 
ci=40; cI=200; r=100;
J = 3; I = 8;

load('j_all_all.mat'); 
% size(j_all_all) = 1000*48 
% 首行为论文数据
N = size(j_all_all, 2); % N为需要计算到的call数，根据需求取
j_all = j_all_all(1, :); % 根据选择j_all中的第几行，此处选择第一行
genPoisson(N);
genPIE(N);
% end global settings <<<

% >>>> 以下部分集成进每个figure函数

%Prop_Policy
%init_time = ftimer(); % set main clock
%[best_is, opt_profits, EYI, EYin, ProfitPart] = prop_policy(j_all, N);

%fprintf("\n\n Prop.Policy Total Time = %.1f seconds \n", ftimer()-init_time);
%display(S);
%display(best_is);
% plot(1:N,opt_profits);
% showTimer();
%------------------------calling other functions------------------------%
%round robin
%init_time = ftimer();
%[i_R, profits_R, EYI, EYin, ProfitPart] = round_robin(j_all, N);
%fprintf("\n\n Round Robin Total Time = %.1f seconds \n", ftimer()-init_time);

%generate a random preference for both policy with preference
%pref = randi([1, 2], 1, N);
%proposed policy with preference
%[best_is_pref, opt_profits_pref] = prop_pref(j_all, pref);
%round robin with preference
%[i_RP, profits_RP] = round_robin_pref(j_all, pref);

% <<<< 

%--------------------------------figures--------------------------------%
%figure 2
disp('--> Figure 2 Runing ...');
figure2(j_all, N);

%figure 3 4
disp('--> Figure 3 & 4 Runing ...');
figure(3);
figure3_4(j_all, N);

%figure 5 9 16
disp('--> Figure 5 & 9 & 16');
load('LINE_2500.mat');
% >>> recommanded 
% Simu_Figure5(LINE_2500);

%[T, Mean, Std, ExpectedProfit, profit_pro, profit_rrall, Histo_5, profit_pmax, best_i,...
% best_ip, Summary, Num_in_slot_p, Percentage_in_slot_p, Figure_9, ImproveRange] = Simu_Figure5 (LINE_2500);




% figure 6
disp('--> Figure 6');
figure6(j_all, N); % P=(0.25,0.5,0.75)

% figure 7
disp('--> Figure 7');
figure7(j_all, N); % P=(0.25,0.5,0.9)

% figure 8
disp('--> Figure 8');
[value] = figure8(j_all, N);

return;
% figure 10 12 14 
global s_time

P = [.25, .5, .75];

s_time = ftimer();
disp('--> Figure 10 & 12 & 14');
figure1x_even(j_all_all);
% input("-->> Press ENTER to continue.\n"); % 暂停程序

% figure 11 13 15 
s_time = ftimer();
disp('--> Figure 11 & 13 & 15');
figure1x_odd(j_all_all);
% input("-->> Press ENTER to continue.\n"); % 暂停程序

